<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="1200px" @open="open" @close="close" top="50px" :append-to-body="true" :modal-append-to-body="true">
    <div style="padding-bottom:10px">
      <div>
        <!-- 列表选择 -->
        <div class="table-alert-div" ref="selector">
          <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
            <template slot="title">
              已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRows.length }}</a
              >项&nbsp;&nbsp;
              <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
            </template>
          </el-alert>
        </div>
        <!--表格渲染-->
        <el-table class="tl-table" ref="mainTable" :height="tableHeight" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" row-key="id" border fit :row-class-name="doChangeRowClassName">
          <el-table-column type="selection" width="55px" fixed="left" v-if="isSingleSelect === false"> </el-table-column>
          <el-table-column prop="taskfeedbackdetail" label="任务更新内容" sortable="custom" sort-by="taskfeedbackdetail" align="left" header-align="center"></el-table-column>
          <el-table-column prop="newamount" label="已交付产品进度" width="130px"  sortable="custom" sort-by="newamount" align="center" header-align="center">
            <template slot-scope="scope">
              {{ scope.row.newamount ? parseInt(scope.row.newamount/scope.row.amount*100) + '%': '——'}}
            </template>
          </el-table-column>
          <el-table-column prop="newfund" label="已完成金额进度" width="130px"  sortable="custom" sort-by="fund" align="center" header-align="center">
            <template slot-scope="scope">
              {{ scope.row.newfund ? parseInt(scope.row.newfund/scope.row.fund*100) + '%': '——'}}
            </template>
          </el-table-column>
          <el-table-column prop="dispstate" label="状态" width="80px" sortable="custom" sort-by="state" align="center" header-align="center"></el-table-column>
          <el-table-column prop="username" label="更新人姓名" width="100px" sortable="custom" sort-by="username" align="center"></el-table-column>
          <el-table-column prop="usercode" label="更新人工号" width="100px" sortable="custom" sort-by="usercode" align="center" header-align="center"></el-table-column>
          <el-table-column prop="feedbackdate" label="更新日期" width="100px" sortable="custom" sort-by="feedbackdate" align="center" header-align="center" :formatter="dateFormat"></el-table-column>
          <el-table-column label="附件" width="130px" sortable="custom" v-slot="scope" sort-by="state" align="center" header-align="center">
            <tl-attachment sourceType="GpmProjectTaskFeedback" :sourceId="scope.row.id" :editable="false"></tl-attachment>
          </el-table-column>
          <el-table-column label="审批历史" width="130px" sortable="custom" sort-by="state" v-slot="scope" align="center" header-align="center">
            <el-button type="primary" @click="openApprovalHistory(scope.row)">审批历史</el-button>
          </el-table-column>
        </el-table>
        <!-- 列表分页 -->
        <el-row class="pagebar" ref="pager">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer" v-if="isSingleSelect === false">
      <el-button type="text" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doConfirm">确认</el-button>
    </div>
    <tl-approval-history ref="history" sourceType="GpmProjectTaskFeedback" :sourceId="approvalHistoryId"></tl-approval-history>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_ref_list } from '@tapui/mixins/mixin_ref_list'
/** 子组件 */
/** 工具类 */
import { queryDataCode } from '@tapui/api/dataCode'
import { getAction, putAction, postAction } from '@tapui/utils/http'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
/** VUE配置 */
export default {
  name: 'TlSdProjectTaskFeedbackRef',
  components: {},
  mixins: [mixin_ref_list],
  data() {
    return {
      description: '项目任务反馈参照页面',
      // 默认Key字段名
      fieldDefaultKey: 'id',
      // 默认显示字段名
      fieldDefaultValue: 'name',
      approvalHistoryId: 0,
      // url配置
      url: {
        list: '/sd/projectTaskFeedback/refList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'feedbackdate',
        sord: 'desc'
      }
    }
  },
  methods: {
    attach(val) {
      console.log(val)
      var a = ''
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      Object.assign(param, this.queryParam, this.externalQueryParam, this.filtersInfo, this.sorterInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.qry_taskid = this.id
      param.qry_state = '1,9'
      return filterObjectNull(param)
    },
    /** 格式化任务进度 */
    percentageFormat(row, column, cellValue, index) {
      let taskScheduleValue = row[column.property]
      if (typeof taskScheduleValue === 'undefined' || taskScheduleValue === null || taskScheduleValue === '') {
        return '0%'
      }
      taskScheduleValue = taskScheduleValue + '%'
      return taskScheduleValue
    },
    // 打开对应的审批历史页面
    openApprovalHistory(row) {
      this.approvalHistoryId = row.id
      this.$refs.history.visible = true
    }
  }
}
</script>

<style lang="scss" scoped>
/** 表格上边、左边的线 */
.el-table--border,
.el-table--group {
  border: none;
}
/**  表格下边的线 */
.el-table--border::before,
.el-table--group::before {
  width: 0;
}
/**  表格右边的线 */
.el-table--border::after,
.el-table--group::after {
  height: 0;
}
/** “暂无数据”居中显示 */
.tl-table {
  /deep/ .el-table__empty-text {
    text-align: center;
  }
  // 控制边框
  /deep/ .gutter {
    display: none !important;
  }
  /deep/ .el-table__header-wrapper .el-table__header {
    table-layout: auto !important;
  }
  /deep/ .el-table__body-wrapper .el-table__body {
    table-layout: auto !important;
  }
}
</style>
